//
// Created by test on 23-2-20.
//
//
// Created by test on 22-11-26.
//
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#include<stdio.h>
#include<iostream>
using namespace std;
int main(int argc,char* argv[]){
    assert(argc>2);
    const char* ip=argv[1];
    int port=atoi(argv[2]);
    struct sockaddr_in address;
    bzero(&address,sizeof(address));
    address.sin_family=AF_INET;
    address.sin_port=htons(port);
    inet_pton(AF_INET,ip,&address.sin_addr);
    int sock=socket(PF_INET,SOCK_STREAM,0);
    int ret=bind(sock,(struct sockaddr*)&address,sizeof(address));
    assert(ret!=-1);
    ret=listen(sock,5);
    assert(ret>=0);
    struct sockaddr_in client;
    socklen_t client_len=sizeof(client);
    ret=accept(sock,(struct sockaddr*)&client,&client_len);
    assert(ret>=0);
    close(STDOUT_FILENO);
    dup(ret);
    std::cout<<"hello"<<std::endl;
    close(ret);
    std::cout<<"bye"<<std::endl;
    close(sock);
    return 0;
}
